package com.ruoyi.web.controller.teacher;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.teacher.domain.SysProfession;
import com.ruoyi.teacher.service.ISysProfessionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Controller
@RequestMapping("/teacher/profession")
public class SysProfessionController extends BaseController
{
    private String prefix = "teacher/profession";

    @Autowired
    private ISysProfessionService sysProfessionService;

    @RequiresPermissions("teacher:profession:view")
    @GetMapping()
    public String profession()
    {
        return prefix + "/profession";
    }

    /**
     * 查询sysProfession列表
     */
    @RequiresPermissions("teacher:profession:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysProfession sysProfession)
    {
        startPage();
        List<SysProfession> list = sysProfessionService.selectSysProfessionList(sysProfession);
        return getDataTable(list);
    }

    /**
     * 导出sysProfession列表
     */
    @RequiresPermissions("teacher:profession:export")
    @Log(title = "sysProfession", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysProfession sysProfession)
    {
        List<SysProfession> list = sysProfessionService.selectSysProfessionList(sysProfession);
        ExcelUtil<SysProfession> util = new ExcelUtil<SysProfession>(SysProfession.class);
        return util.exportExcel(list, "专业数据");
    }

    @RequiresPermissions("teacher:profession:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<SysProfession> util = new ExcelUtil<SysProfession>(SysProfession.class);
        return util.importTemplateExcel("专业数据");
    }

    /**
     * 新增sysProfession
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存sysProfession
     */
    @RequiresPermissions("teacher:profession:add")
    @Log(title = "sysProfession", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysProfession sysProfession)
    {
        sysProfession.setCreateBy(getLoginName());

        return toAjax(sysProfessionService.insertSysProfession(sysProfession));
    }

    /**
     * 修改sysProfession
     */
    @RequiresPermissions("teacher:profession:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysProfession sysProfession = sysProfessionService.selectSysProfessionById(id);
        mmap.put("sysProfession", sysProfession);
        return prefix + "/edit";
    }

    /**
     * 修改保存sysProfession
     */
    @RequiresPermissions("teacher:profession:edit")
    @Log(title = "sysProfession", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysProfession sysProfession)
    {
        sysProfession.setUpdateBy(getLoginName());
        return toAjax(sysProfessionService.updateSysProfession(sysProfession));
    }

    /**
     * 删除sysProfession
     */
    @RequiresPermissions("teacher:profession:remove")
    @Log(title = "sysProfession", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysProfessionService.deleteSysProfessionByIds(ids));
    }


}
